#ifndef TEXTURE_CONTROL_H
#define TEXTURE_CONTROL_H

#include <map>
#include <set>
#include <vector>
#include <string>
#include <windows.h>
#include <stdio.h>
#include <gl\gl.h>
#include <gl\glu.h>
#include "Math/MathCode.h"

typedef struct ImageData {
  GLuint image_index;
  int offset;
  int width;
  int height;
  int bits;
} ImageData;

class TextureControl {
  public:
    typedef std::map< std::string, ImageData > TexMap;
    typedef TexMap::iterator TexIter;
    typedef std::pair< std::string, ImageData > TexPair;
    typedef std::pair< TexIter, bool > TexInsert;

    bool LoadTexture( std::string filename, int warp );
    void RemoveTexture( std::string filename );
    void ClearTextures();

    GLuint FindTextureID( std::string name );
    bool BindTexture( GLuint index );
    bool BindTexture( std::string filename );
  private:
    TexMap nameToTexture;
};

struct GraphicObject {
  GraphicObject() : textureId(0),
                    translation( Vector3f() ),
                    rotation( 0 ),
                    scale( NewVector(1.0f,1.0f,1.0f) )
  {}

  GLuint textureId;

  Vector3f translation;
  float rotation;
  Vector3f scale;
};

class GraphicsSystem : public TextureControl {
  public:
    GraphicsSystem();
    int CreateGraphicsObject();
    bool DestroyGraphicsObject( int ID ); 

    GraphicObject& LocateObject( int ID );
    int LocateUsedID();

    std::vector< GraphicObject >& GetObjects();
  private:
    std::set<int> removedIdLocations;
    std::vector< GraphicObject > graphicsObjects;
};

void OpenGLSetup();
void DrawSquare( GraphicObject& obj );
void Draw( std::vector<GraphicObject>& objects );

unsigned int AddGraphicObject( std::string texName, int x, int y, int scaleX, int scaleY );
void DeleteGraphicObject( unsigned int index );


#endif
